package com.study.controller;

import com.alibaba.fastjson.JSON;
import com.study.domain.Order;
import com.study.domain.Product;
import com.study.service.OrderService;
import com.study.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * @author MI
 * @version 1.0
 * @date 2020/10/18 17:30
 */
// @RestController
// @RequestMapping("/order")
@Slf4j
public class OrderControler2 {


    @Autowired
    OrderService orderService;
    @Autowired
    ProductService productService;

    @RequestMapping("/prod/{pid}")
    public Order order(@PathVariable("pid") Integer pid) {
        log.info("接收到 { } 商品的下单请求", pid);
        //调用商品查询商品信息
        Product product = productService.findByPid(pid);
        log.info("查询到{}商品信息是", pid, JSON.toJSONString(product));
        final Order order = new Order();
        log.info("FeignClient 测试");
        order.setUid(1);
        order.setUsername("测试用户");

        order.setPid(pid);
        order.setNumber(1);
        order.setPname(product.getPname());
        order.setPprice(product.getPprice());

        // orderService.createOrder(order);
        log.info("订单完成{}", JSON.toJSONString(order));
        return order;
    }

    //测试高并发
    @GetMapping("message")
    public String msg() {
        return "测试高并发";
    }
}
